package com.itheima.sh.indent.service.impl;


import com.itheima.sh.indent.mapper.OrderMapper;
import com.itheima.sh.indent.service.IndentService;
import com.itheima.sh.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class IndentServiceFeignImpl implements IndentService {
    @Autowired
    OrderMapper orderMapper;
    /**
     * 根据主键用户名查询订单列表
     * @param username 登录用户名
     * @return
     */
    @Override
    public List<Order> findOrderByUserId(String username) {

        if ("lisi".equals(username)) {
            throw new RuntimeException("测试异常");
        }


        // 创建条件查询对象
        Example example = new Example(Order.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isEmpty(username)) {
            throw new RuntimeException("参数不能为空");
        }
        criteria.andEqualTo("username", username);

        List<Order> orderList = orderMapper.selectByExample(example);
        return orderList;
    }
}
